﻿using System;
using T.FAS.Runtime.DataAccess.Engine.ValidateChecker.Entity;

namespace T.FAS.Runtime.DataAccess.Engine
{
    public class DateValidateFactory : CommonFactory
    {
        public override IColumnValidater GetDataTypeValidater()
        {
            return new DateDataTypeValidater();
        }
        public override IColumnValidater GetLengthValidater()
        {
            return new DateDataTypeValidater();
        }
    }

    public class DateDataTypeValidater : IColumnDataTypeValidater
    {
        public ValidateCheckItem Validate(ValidateCheckItem item)
        {
            if (item.Result.IsStop)
                return item;
            //数据类型验证
            var inputVal = item.InputValue.ToString();
            if (!DateTime.TryParse(inputVal, out DateTime value))
            {
                item.Result.Flag = false;
                item.Result.IsStop = true;
                item.Result.Msg.Append(string.Format(ValidateConst.DataTypeErrorTemp, item.CheckElement.Name, inputVal, item.CheckElement.DataType));
            }
            else
            {
                item.ConvertValue = value;
            }
            return item;
        }
    }

    public class DateLengthValidater : IColumnLengthValidater
    {
        /// <summary>
        /// Boolean默认不用校验长度
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public ValidateCheckItem Validate(ValidateCheckItem item)
        {
            return item;
        }
    }
}
